/**
 * 
 */

package handler.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public class LoggingInterceptor extends HandlerInterceptorAdapter
{

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#afterCompletion(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse, java.lang.Object, java.lang.Exception)
	 */
	@Override
	public void afterCompletion( HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex ) throws Exception
	{
		System.out.println( "====================================================================" );
		System.out.println( "handler in method afterCompletion():" + handler.getClass().getName() );
		System.out.println( "View 繪製完成之後, 會被執行的 method afterCompletion()" );
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#postHandle(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.web.servlet.ModelAndView)
	 */
	@Override
	public void postHandle( HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView )
		throws Exception
	{
		System.out.println( "====================================================================" );
		System.out.println( "handler in method postHandle():" + handler.getClass().getName() );
		System.out.println( "Controller 處理完請求之後, 會被執行的 method postHandle()" );
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse, java.lang.Object)
	 */
	@Override
	public boolean preHandle( HttpServletRequest request, HttpServletResponse response, Object handler ) throws Exception
	{
		
		System.out.println( "handler in method preHandle():" + handler.getClass().getName() );
		System.out.println( "Controller 處理請求之前, 會被執行的 method preHandle()" );

		// if return false, 那麼接下來的 Interceptor or Controller 就不處理請求
		return true;
	}

}
